<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
</head>

<body>
	<script>
		function sum(...args) {
			let addNum = reduceNum(args)
			function add(...argsOther) {
				addNum += reduceNum(argsOther)
				return add
			}
			add.value = () => {
				return addNum
			}

			function reduceNum(arr) {
				return arr.reduce((result, item) => result + item, 0)
			}

			return add
		}

		/*
		实现 Sum 函数链式调用计算多数之和，可通过 sum()().value() 获取计算结果。
		系统将调用Sum(1)(2)(3, 4).value()、Sum(1)(2)(3)(4)(5).value()、Sum(1,2)(3,4).value()等测试用例进行验证
		
		function Sum(...args) {
			let total = args.reduce((acc, curr) => acc + curr, 0);

			const innerSum = (...newArgs) => {
				total += newArgs.reduce((acc, curr) => acc + curr, 0);
				return innerSum;
			};

			innerSum.value = () => total;

			return innerSum;
		} */





	</script>
</body>

</html>